describe('document parse', function() {
    var div1, t1, data1, d1, str;

    beforeEach(function() {
        $.ajax = mocka.mockView()
        div1 = setFixtures("<div id='div1'></div>")
        data1 = {
            value: "value",
            duplex: "duplex",
            text: "text"

        }
        str = "str"
    })
    afterEach(function() {
        jc.config.interpolate(["{{", "}}"])
        session = {}
    })
    it('the config about interpolate works', function() {
        var fakeDiv = setFixtures("<div>_#a#_</div>")
        jc.config.interpolate(["_#", "#_"])
        scanNodes(fakeDiv[0], {
            a: 321
        })
        expect(fakeDiv).toContainText("321")
    });


    describe('scanExpr', function() {
        it("can parse expr without value only filters", function() {
            expect(scanExpr("{{|abc}}").value).toEqual(undefined)
        })
        it("can parse expr which starts with '#'", function() {
            expect(scanExpr("{{#ab|abc}}")[0].needWatch).toEqual(true)
        })
    })
    describe("tag and text express", function() {
        beforeEach(function() {
            jc.render(data1, "documentParseSpec_1", div1, function() {
                t1 = jc.th(div1)
                d1 = t1.data()
            })
        })
        describe("jc-bind tag", function() {

            it("can bind the form to template data", function() {

                var input = div1.find('#bind')
                var event = document.createEvent("Event")
                event.initEvent("input", true, true)
                input.val(str)
                input[0].dispatchEvent(event)
                expect(input.val()).toBe(str)
                expect(d1.value).toBe(str)
            })
        })
        describe('jc-duplex tag', function() {
            var input, event;
            beforeEach(function() {
                input = div1.find('#duplex')
            })

            it("can bind the form to template data", function() {
                event = document.createEvent("Event")
                event.initEvent("input", true, true)
                input.val(str)
                input[0].dispatchEvent(event)
                expect(input.val()).toBe(str)
                expect(d1.duplex).toBe(str)
            })

            it("can listen to template data", function() {
                d1.duplex = str
                expect(input.val()).toBe(str)
            })
        });

        describe("text expression", function() {
            var text;
            beforeEach(function() {
                text = div1.find('#text')
            })
            it('can listen to template data', function() {
                d1.text = str
                expect(text.text()).toBe(str)
            });
        })
    })

});